# 发送附件邮件

import smtplib
from email.mime.text import MIMEText
from email.header import Header
from email.mime.application import MIMEApplication
from email.mime.multipart import MIMEMultipart

# 登录邮箱
smtp_obj = smtplib.SMTP("smtp.163.com")
smtp_obj.login("18735816507@163.com","授权密码")

# 编辑内容
mail_text = '''
<h1>标题一</h1>
<p>This is Email~</p>
<p><a href='http://www.baidu.com'>百度一下~</a></p>
'''

# 编写文本内容
msg_body = MIMEText(mail_text, 'html', 'utf-8')
# 增加附件
file = MIMEApplication(open('../1.office_cases/03.py_pdf/02.py_pdfFile/01.京A00000违章通知书.pdf', 'rb').read())
file.add_header('Content-Disposition', 'attachment', filename='wb.pdf')
# 封装邮件
multi_part = MIMEMultipart()
multi_part.attach(msg_body)
multi_part['From'] = Header('Python测试发件人', 'utf-8')
multi_part['Subject'] = Header('Python测试发邮件主题', 'utf-8')
multi_part.attach(file)

# 发送邮件
smtp_obj.sendmail("18735816507@163.com", ["xxacker@163.com"], multi_part.as_string())




